package com.designer.shapes
{
	
	public class Star extends GeometricShape
	{
		private var _nPoints:uint = 5;
		private var _nLength:Number = 10;
		private var _nInnerRadius:Number = 10;
		private var _nOuterRadius:Number = 30;
		
		public function Star(lineColor:Number=0, lineThickness:Number=0, lineAlpha:Number=1, fillColor:Number=0, fillAlpha:Number=1, nPoints:uint=5, xStart:Number=0, yStart:Number=0, xFinal:Number=0, yFinal:Number=0) {
			super("star", lineColor, lineThickness, lineAlpha, fillColor, fillAlpha, xStart, yStart, xFinal, yFinal);
			_nPoints = nPoints;
			_nLength = Math.sqrt((xFinal - xStart)*(xFinal - xStart) + (yFinal - yStart)*(yFinal - yStart));
			draw();
		}
		
		public override function draw():void
		{
			
			this.graphics.clear();
			
			if(_nPoints < 3) {
				return;
			}
			
			this.graphics.lineStyle(1.0, lineColor, 1.0);
			this.graphics.beginFill(fillColor, 1.0);
			
			var nX:Number = xStart;
			var nY:Number = yStart;
			
			var nAngleDelta:Number = (Math.PI * 2) / _nPoints;
			
			_nLength = Math.sqrt((xFinal - xStart)*(xFinal - xStart) + (yFinal - yStart)*(yFinal - yStart));
			var nRotation:Number = Math.asin((yFinal-yStart)/_nLength);
			
			_nInnerRadius = _nLength / 3;
			_nOuterRadius = _nLength;
			
			//nRotation = Math.PI * (nRotation - 90) / 180;
			
		 	var nAngle:Number = nRotation;
			
			var nPenX:Number = nX + Math.cos(nAngle + nAngleDelta / 2) * _nInnerRadius;
			var nPenY:Number = nY + Math.sin(nAngle + nAngleDelta / 2) * _nInnerRadius;
			
			this.graphics.moveTo(nPenX, nPenY);
			
			nAngle += nAngleDelta;
			
			for(var i:Number = 0; i < _nPoints; i++) {
				nPenX = nX + Math.cos(nAngle) * _nOuterRadius;
				nPenY = nY + Math.sin(nAngle) * _nOuterRadius;
				this.graphics.lineTo(nPenX, nPenY);
				nPenX = nX + Math.cos(nAngle + nAngleDelta / 2) * _nInnerRadius;
				nPenY = nY + Math.sin(nAngle + nAngleDelta / 2) * _nInnerRadius;
				this.graphics.lineTo(nPenX, nPenY);
				nAngle += nAngleDelta;
			}
			this.graphics.endFill();
		}		
	}
}